#include<stdio.h>
#include<time.h>
#include<stdlib.h>

int main()
{
	int length = 9;
	char * s = (char *)malloc(length+1);
	char * r = (char *)malloc(length+1);	
	time_t now = 0;
	int n = 0;	

	do
	{
		int num = 0;
		srand(time(NULL));
		for (n = 0; n < length; n ++)
		{
			num = num * 10 + rand()%10;
			while (num == 0)
			{
				num = rand()%10;
			}
		}
		sprintf(s, "%d", num);
		printf("The Number is %s", s);
		fflush(stdout);

		now = clock();
		for(;clock() - now < 3*CLOCKS_PER_SEC;);
		
		for (n = 0; n < length; n ++)
		{
			printf(" ");
		}
		printf("\r");
		printf("Please enter the number:");
		__fpurge(stdin);						
		gets(r);
		if(!strcmp(s,r))
		{
			printf("Oh right! U Win!\n");	
		}
		else
		{
			printf("Sorry, u a wrong! The number is: %s\n", s);
		}
		printf("Do u want to play again? (y or n)\n");
	} while(getchar() == 'y');
	free(s);
	free(r);
	return 0;
}
